package com.cn.plugin.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.Properties;

/**
 * @author : Hydra
 * @date: 2021/3/20 13:57
 * @version: 1.0
 */
@Slf4j
@Intercepts({
        @Signature(type = Executor.class,method = "query", args = { MappedStatement.class, Object.class,
                RowBounds.class, ResultHandler.class })
})
public class MyPlugin2 implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        log.info("plugin2 : 执行 intercept() 方法");
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        if(target instanceof Executor){
            log.info("plugin2 : 执行 plugin() 方法");
            Object wrap = Plugin.wrap(target, this);
            return wrap;
        }
        return target;
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
